home *** CD-ROM | disk | FTP | other *** search
- // sockinet.h -*- C++ -*- socket library
- // Copyright (C) 1992,1993 Gnanasekaran Swaminathan <gs4t@virginia.edu>
- //
- // Permission is granted to use at your own risk and distribute this software
- // in source and binary forms provided the above copyright
- // notice and this paragraph are preserved on all copies.
- // This software is provided "as is" with no express or implied warranty.
- //
- // Version: 31Jan93 1.3
-
- #ifndef _SOCKINET_H
- #define _SOCKINET_H
-
- #include <sockstream.h>
- #include <netinet/in.h>
-
- class sockinetaddr: public sockAddr, public sockaddr_in {
- protected:
- void setport (const char* sn, const char* pn="tcp");
- void setaddr (const char* hn);
- public:
- sockinetaddr ();
- sockinetaddr (unsigned long addr, int port_no=0);
- sockinetaddr (const char* host_name, int port_no=0);
- sockinetaddr (unsigned long addr,
- const char* service_name,
- const char* protocol_name="tcp");
- sockinetaddr (const char* host_name,
- const char* service_name,
- const char* protocol_name="tcp");
- operator void* () const { return (sockaddr_in*)this; }
-
- int size() const { return sizeof (sockaddr_in); }
- int family() const { return sin_family; }
-
- int getport() const { return ntohs (sin_port); }
- const char* gethostname() const;
- };
-
- class sockinetbuf: public sockbuf {
- protected:
- sockinetbuf& operator=(sockbuf& si); // needs to be fixed
- public:
- enum domain { af_inet = 2 };
-
- sockinetbuf (const sockbuf& si): sockbuf(si) {}
- sockinetbuf (sockbuf::type ty, int proto=0);
-
- sockbuf* open (sockbuf::type, int proto=0);
-
- sockinetaddr localaddr() const;
- int localport() const;
- const char* localhost() const;
-
- sockinetaddr peeraddr() const;
- int peerport() const;
- const char* peerhost() const;
-
- virtual void bind (sockAddr& sa);
- void bind ();
- void bind (unsigned long addr, int port_no=0);
- void bind (const char* host_name, int port_no=0);
- void bind (unsigned long addr,
- const char* service_name,
- const char* protocol_name="tcp");
- void bind (const char* host_name,
- const char* service_name,
- const char* protocol_name="tcp");
-
- virtual void connect (sockAddr& sa);
- void connect (unsigned long addr, int port_no=0);
- void connect (const char* host_name, int port_no=0);
- void connect (unsigned long addr,
- const char* service_name,
- const char* protocol_name="tcp");
- void connect (const char* host_name,
- const char* service_name,
- const char* protocol_name="tcp");
-
- };
-
- class isockinet: public isockstream
- {
- public:
- isockinet (const sockbuf& sb);
- isockinet (sockbuf::type ty=sockbuf::sock_stream,
- int proto=0);
- isockinet (sockinetbuf* sb, ostream* tied=0)
- : ios (sb, tied) { setf (ios::dont_close); }
-
- sockinetbuf* rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
- sockinetbuf* operator -> () { return rdbuf (); }
- };
-
- class osockinet: public osockstream
- {
- public:
- osockinet (const sockbuf& sb);
- osockinet (sockbuf::type ty=sockbuf::sock_stream,
- int proto=0);
- osockinet (sockinetbuf* sb, ostream* tied=0)
- : ios (sb, tied) { setf (ios::dont_close); }
-
- sockinetbuf* rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
- sockinetbuf* operator -> () { return rdbuf (); }
- };
-
- class iosockinet: public iosockstream
- {
- public:
- iosockinet (const sockbuf& sb);
- iosockinet (sockbuf::type ty=sockbuf::sock_stream,
- int proto=0);
- iosockinet (sockinetbuf* sb, ostream* tied=0)
- : ios (sb, tied) { setf (ios::dont_close); }
-
- sockinetbuf* rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
- sockinetbuf* operator -> () { return rdbuf (); }
- };
-
- #endif _SOCKINET_H
-